
from web import models
from django import forms
from utils.BootStrapForm import BootStrapForm

class WikiModelForm(BootStrapForm,forms.ModelForm):

    bootstrap_class_exclude = ['project','depth',]
    class Meta:
        model = models.Wiki
        fields = ['title','content','parent']

    def __init__(self,request,*args,**kwargs):
        super().__init__(*args,**kwargs)
    ## 重写自关联字段的显示，只让其显示这个项目的数据，不要全部显示出来。只获取项目的id和项目的名字
        total_data_list = [("","请选择"),]
        data_list = models.Wiki.objects.filter(project=request.tracer.project).values_list('id','title')
        total_data_list.extend(data_list)
        self.fields['parent'].choices = total_data_list # 让下拉框显示自定义的choices数据

















